package com.lvy.hczn.front.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lvy.hczn.front.common.core.text.Convert;
import com.lvy.hczn.front.system.domain.business.TemperatureZone;
import com.lvy.hczn.front.system.mapper.TemperatureZoneMapper;
import com.lvy.hczn.front.system.mapper.WarehouseMapper;
import com.lvy.hczn.front.system.service.TemperatureZoneService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class TemperatureZoneServiceImpl extends ServiceImpl<TemperatureZoneMapper, TemperatureZone> implements TemperatureZoneService {

    @Autowired
    private TemperatureZoneMapper temperatureZoneMapper;

    /**
     * 查询温区信息
     *
     * @param id 温区信息主键
     * @return 温区信息
     */
    @Override
    public TemperatureZone selectTemperatureZoneById(String id) {
        return super.getById(id);
    }

    /**
     * 查询温区信息列表
     *
     * @param temperatureZone 温区信息
     * @return 温区信息
     */
    @Override
    public List<TemperatureZone> selectTemperatureZoneList(TemperatureZone temperatureZone) {
        return temperatureZoneMapper.selectTemperatureZoneList(temperatureZone);
    }

    /**
     * 新增温区信息
     *
     * @param temperatureZone 温区信息
     * @return 结果
     */
    @Override
    public int insertTemperatureZone(TemperatureZone temperatureZone) {
        if (super.save(temperatureZone)) {
            return 1;
        } else {
            return 0;
        }
    }

    /**
     * 修改温区信息
     *
     * @param temperatureZone 温区信息
     * @return 结果
     */
    @Override
    public int updateTemperatureZone(TemperatureZone temperatureZone) {
        return temperatureZoneMapper.updateById(temperatureZone);
    }

    /**
     * 批量删除温区信息
     *
     * @param ids 需要删除的温区信息主键
     * @return 结果
     */
    @Override
    public int deleteTemperatureZoneByIds(String ids) {
        String[] arrayId = Convert.toStrArray(ids);
        for (String id : arrayId) {
            super.removeById(id);
        }
        return arrayId.length;
    }

    /**
     * 删除温区信息信息
     *
     * @param id 温区信息主键
     * @return 结果
     */
    @Override
    public int deleteTemperatureZoneById(String id) {
        return super.removeById(id) == true ? 1 : 0;
    }
}
